package com.huaao.micropolice.core.model.system;

import java.io.Serializable;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * @author qiyang
 * 操作菜单
 * @version 1.0
 */
public class Menu implements Serializable , Comparable<Menu>{
	private String id;
	private String name;
	private Integer sort = 0;
	private Integer level;
	private String permission;
	private String icon;
	private String url;
	private Menu parent;
	private Set<Menu> children = new LinkedHashSet<Menu>();
	
	private List<Menu> sortChildren = new LinkedList<Menu>();
	
	private Set<Role> roles = new LinkedHashSet<Role>();
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Integer getSort() {
		return sort;
	}
	public void setSort(Integer sort) {
		this.sort = sort;
	}
	public Integer getLevel() {
		return level;
	}
	public void setLevel(Integer level) {
		this.level = level;
	}
	public String getPermission() {
		return permission;
	}
	public void setPermission(String permission) {
		this.permission = permission;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public Menu getParent() {
		return parent;
	}
	public void setParent(Menu parent) {
		this.parent = parent;
	}
	public Set<Menu> getChildren() {
		return children;
	}
	public void setChildren(Set<Menu> children) {
		this.children = children;
	}
	public Set<Role> getRoles() {
		return roles;
	}
	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}
	
	public List<Menu> getSortChildren() {
		sortChildren.addAll(children);
		Collections.sort(sortChildren);
		return sortChildren;
	}
	
	public void setSortChildren(List<Menu> sortChildren) {
		this.sortChildren = sortChildren;
	}
	
	@Override
	public int compareTo(Menu o) {
		return this.sort.compareTo(o.getSort());
	}
}
